namespace Example.Web
{
    using System.Xml.Serialization;
    using System.Xml.XPath;
    using SimpleWebServices;
    using SimpleWebServices.Web.UI.Html.Elements;
    using Xunit;

    public sealed class ExampleChoiceFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<ExampleChoice>()
                .DerivesFrom<Fieldset>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("fieldset")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            ExampleChoice expected = new ExampleChoice();

            string xml = "<fieldset />";
            ExampleChoice actual = xml.Deserialize<ExampleChoice>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void serialize()
        {
            XPathNavigator navigator = new ExampleChoice().Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/fieldset[@id='choice'])"));
            Assert.True((bool)navigator.Evaluate("1=count(/fieldset[@id='choice']/legend[@id='legend-choice'])"));
            Assert.True((bool)navigator.Evaluate("1=count(/fieldset[@id='choice']/legend[@id='legend-choice']/span[@class='error'])"));

            Assert.True((bool)navigator.Evaluate("0 != string-length(/fieldset[@id='choice']/p/input[@type='radio'][@name='choice'][@value='1'][@id='choice:1']/@title)"));
            Assert.True((bool)navigator.Evaluate("0 != string-length(/fieldset[@id='choice']/p/label[@for='choice:1'][@id='label-choice:1']/text())"));

            Assert.True((bool)navigator.Evaluate("0 != string-length(/fieldset[@id='choice']/p/input[@type='radio'][@name='choice'][@value='2'][@id='choice:2']/@title)"));
            Assert.True((bool)navigator.Evaluate("0 != string-length(/fieldset[@id='choice']/p/label[@for='choice:2'][@id='label-choice:2']/text())"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new ExampleChoice());
        }

        [Fact]
        public void prop_Disabled()
        {
            Assert.True(new PropertyExpectations(typeof(ExampleChoice).GetProperty("Disabled"))
                .IsAutoProperty<bool>()
                .Result);
        }

        [Fact]
        public void prop_TabIndex()
        {
            Assert.True(new PropertyExpectations(typeof(ExampleChoice).GetProperty("TabIndex"))
                .IsAutoProperty<int?>()
                .Result);
        }
    }
}